package com.haoran.dwz.config;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.haoran.dwz.hystrix.UsmHystrixCommandWapper;
import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;

@Configuration
public class HystrixServiceConfig {
	@Bean
	public HystrixCommandAspect hystrixAspect() {
		return new HystrixCommandAspect();
	}

	@Bean
	public UsmHystrixCommandWapper initUsmHystrixRpcWrapper() {
		return new UsmHystrixCommandWapper();
	}

	@Bean
	public HystrixMetricsStreamServlet hystrixMetricsStreamServlet() {
		return new HystrixMetricsStreamServlet();
	}

	@Bean
	public ServletRegistrationBean registerHystrixMetricsStreamServlet(
			HystrixMetricsStreamServlet hystrixMetricsStreamServlet) {
		ServletRegistrationBean registrationBean = new ServletRegistrationBean();
		registrationBean.setServlet(hystrixMetricsStreamServlet);
		registrationBean.setEnabled(true);
		registrationBean.addUrlMappings("/hystrix.stream");
		return registrationBean;
	}
}
